package reg

import (
	"github.com/astaxie/beego/context"
	"svntool/application/models/roles"
	"svntool/application/models/user"
)

//初始化用户权限
var initUserRole = func(uid int){
	role_builder := roles.RoleBuilder{}
	role_builder.InitUserRoles(uid)
}

type Role_account struct {
	Account user.Account_interface
	LineToolReg LinetoolRegInterface
} 

func (ra *Role_account) Register(ctx *context.Context) (info map[string]interface{}, err error) {
	if ok,err := ra.LineToolReg.Check(ctx); !ok {
		return nil, err
	}
	result, err := ra.Account.Register(ctx)
	if err != nil{
		return nil, err
	}
	uid := int(result["uid"].(int64))
	//初始化用户权限
	initUserRole(uid)
	ra.LineToolReg.Reg(ctx)
	return result, nil
}